package com.ybwh.springboot1.conf;

import com.ybwh.datasource.refreshable.druid.DruidRefreshDataSource;
import com.ybwh.datasource.refreshable.druid.DruidRefreshDataSourceProperties;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>
 * 数据源的配置
 * </p>
 *
 * @author fanbeibei
 * @version V1.0
 * @since 2019/4/5 21:32
 */
//@Configuration
@Data
public class DataSourceConfig {
    @Value("${datasource.druid.url}")
    private String url;
    @Value("${datasource.druid.username}")
    private String username;
    @Value("${datasource.druid.password}")
    private String password;
    @Value("${datasource.druid.driver-class-name}")
    private String driverClassName;


    @Bean(name = "dataSource", initMethod = "init", destroyMethod = "destroy")
    public DruidRefreshDataSource dataSource() {
        DruidRefreshDataSourceProperties properties = new DruidRefreshDataSourceProperties();
        properties.setUrl(url);
        properties.setUsername(username);
        properties.setPassword(password);
        properties.setDriverClassName(driverClassName);

        DruidRefreshDataSource dataSource = new DruidRefreshDataSource(properties);

         return dataSource;
    }


}
